package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.dao.ZLContentdao;
import com.zr.dao.impl.ZLContentdaoimpl;

import net.sf.json.JSONObject;

public class ZLknowledgeaction extends  HttpServlet{
 /*
  * 知识板块展示
  * */
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
		protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			resp.setCharacterEncoding("utf8");
			resp.setCharacterEncoding("utf8");
			//获得当前页数，和行数
			String page = req.getParameter("page");
			String row = req.getParameter("rows");
			String lx = req.getParameter("lx");
			String ss = req.getParameter("ss");
			String id = req.getParameter("id");
			int i = Integer.parseInt(id);
			if("".equals(ss))
			{ i =0; }
			ZLContentdao zlc = new ZLContentdaoimpl();
			JSONObject json = new JSONObject();
			int state = (Integer.parseInt(page)-1)*Integer.parseInt(row);
			int rows  = Integer.parseInt(row);
			
			if(i == 0)
			{   
				if(lx==null)
				{
				String[] sss = new String[]{};
			    json.put("rows", zlc.Contentshow(state, rows));
				json.put("total", zlc.Contentcount(sss, lx, i));
				PrintWriter  pw = resp.getWriter();
				pw.write(json.toString());
				}
				else
				{
					json.put("rows", zlc.lxContentshow(state, rows, lx));
					json.put("total", zlc.lxContentcount(lx));
					PrintWriter  pw = resp.getWriter();
					pw.write(json.toString());
					
				}
			}
			else if(i == 1)
			{
				String[] sss = ss.split(" ");
				
				json.put("rows", zlc.ssbtContentshow(state, rows, sss,lx));
				json.put("total", zlc.Contentcount(sss, lx, i));
				PrintWriter  pww = resp.getWriter();
				pww.write(json.toString());
				
				
			}
			else
			{   
				
				String[] ssss = ss.split(" ");
				int jj=0;
				for (String string : ssss) {
					jj++;
				}
				String[] sss = new String[jj] ;
				int j =0;
				for (String s : ssss) {
					if("".equals(s))
					{
						continue;
					}
					sss[j++]=s;
				}
				json.put("rows", zlc.sslrContentshow(state, rows, sss,lx));
				json.put("total", zlc.Contentcount(sss, lx, i));
				PrintWriter  pww = resp.getWriter();
				pww.write(json.toString());
			}
			
		}
	

	
	
}
